package com.dao.lqj;

import com.dao.BaseDao;
import com.entity.User;
import com.service.UserService;
import com.utils.EncryptCodeUtils;

public class LoginDao extends BaseDao {
    /**
     * 登录Sql语句
     * @param
     * @return
     */



    public User Login(String userName , String passWord) {

        UserService userService = new UserService();
        String sql = "select * from user where userName = ? and passWord = ?";
        User user = userService.queryUserByUsername(userName);
        String msg = "";
        if (user == null) {
            msg = "用户不存在！！！";
        } else {
            //先把传递过来的密码加密一遍
            String encryptPwd = EncryptCodeUtils.getEncryptStr(passWord, user.getPhone());
            if (user.getPassword().equals(encryptPwd)) {
                msg = "登陆成功";
//                session.setAttribute("msg", msg);
//                session.setAttribute("flag", true);

                //多长时间没有操作页面就T出去
                //session.setMaxInactiveInterval(3*60);
                //清空
                //session.invalidate();
                //移除
                //session.removeAttribute("house");
                //直接到首页

            } else {
                msg = "密码错误！！！";
            }

        }
        return user;
    }

    public static void main(String[] args) {
        User login = new LoginDao().Login("123456", "123456");
        System.out.println(login);
    }
}